module.exports   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 9.4285
1
module.exports = function(GedcomX){
2
3
  var utils = require('../utils'),
4
      AtomCommon = require('./AtomCommon');
5
  
6
  /**
7
   * Common schema for atom authors and contributors.
8
   * 
9
   * @see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/atom-model-specification.md#atom-json-media-type|GEDCOM X Atom JSON Spec}
10
   * @see {@link https://tools.ietf.org/html/rfc4287#appendix-B|RFC 4287}
11
   * 
12
   * @class AtomPerson
13
   * @extends AtomCommon
14
   * @param {Object} [json]
15
   */
16
  var AtomPerson = function(json){
17
    
18
    // Protect against forgetting the new keyword when calling the constructor
19
    if(!(this instanceof AtomPerson)){
20
      return new AtomPerson(json);
21
    }
22
    
23
    // If the given object is already an instance then just return it. DON'T copy it.
24
    if(AtomPerson.isInstance(json)){
25
      return json;
26
    }
27
    
28
    this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
29
  };
30
  
31
  AtomPerson.prototype = Object.create(AtomCommon.prototype);
32
  
33
  AtomPerson._gedxClass = AtomPerson.prototype._gedxClass = 'GedcomX.AtomPerson';
34
  
35
  AtomPerson.jsonProps = [
36
    'uri',
37
    'name',
38
    'email'
39
  ];
40
  
41
  /**
42
   * Check whether the given object is an instance of this class.
43
   * 
44
   * @param {Object} obj
45
   * @returns {Boolean}
46
   */
47
  AtomPerson.isInstance = function(obj){
48
    return utils.isInstance(obj, this._gedxClass);
49
  };
50
51
  /**
52
   * Initialize from JSON
53
   * 
54
   * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
55
   * @return {AtomPerson} this
56
   */
57
  AtomPerson.prototype.init = function(json){
58
    
59
    AtomCommon.prototype.init.call(this, json);
60
    
61
    if(json){
62
      this.setUri(json.uri);
63
      this.setName(json.name);
64
      this.setEmail(json.email);
65
    }
66
    return this;
67
  };
68
  
69
  /**
70
   * Set the uri
71
   * 
72
   * @param {String} uri
73
   * @return {AtomPerson} this
74
   */
75
  AtomPerson.prototype.setUri = function(uri){
76
    this.uri = uri;
77
    return this;
78
  };
79
  
80
  /**
81
   * Get the uri
82
   * 
83
   * @return {String} this
84
   */
85
  AtomPerson.prototype.getUri = function(){
86
    return this.uri;
87
  };
88
  
89
  /**
90
   * Set the name
91
   * 
92
   * @param {String} name
93
   * @return {AtomPerson} this
94
   */
95
  AtomPerson.prototype.setName = function(name){
96
    this.name = name;
97
    return this;
98
  };
99
  
100
  /**
101
   * Get the name
102
   * 
103
   * @return {String} this
104
   */
105
  AtomPerson.prototype.getName = function(){
106
    return this.name;
107
  };
108
  
109
  /**
110
   * Set the email
111
   * 
112
   * @param {String} email
113
   * @return {AtomPerson} this
114
   */
115
  AtomPerson.prototype.setEmail = function(email){
116
    this.email = email;
117
    return this;
118
  };
119
  
120
  /**
121
   * Get the name
122
   * 
123
   * @return {String} this
124
   */
125
  AtomPerson.prototype.getEmail = function(){
126
    return this.email;
127
  };
128
  
129
  /**
130
   * Export the object as JSON
131
   * 
132
   * @return {Object} JSON object
133
   */
134
  AtomPerson.prototype.toJSON = function(){
135
    return this._toJSON(AtomCommon, AtomPerson.jsonProps);
136
  };
137
  
138
  GedcomX.AtomPerson = AtomPerson;
139
140
};